/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-03-22 08:39:42
 * @LastEditors: voanit
 * @LastEditTime: 2022-03-22 09:06:21
 */
var book = [
  { id: 1, name: '水浒传' },
  { id: 2, name: '西游记' },
]
export default function user(state = book, action) {
  switch (action.type) {
    case 'book/add':
      return [...state, { id: 3, name: '红楼梦' }]
    case 'book/update':
      return state.map((item) => {
        if (item.id === action.payload.id) {
          return {
            ...item,
            name: action.payload.name,
          }
        }
        return item
      })
    default:
      return state
  }
}
